package com.jinlejia.erp.ui.access_manager;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.ActivityAccessManagerBinding;
import com.sevenheaven.segmentcontrol.SegmentControl;

/**
 * 带看管理
 */
public class AccessManagerActivity extends AppCompatActivity {
    private ActivityAccessManagerBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_access_manager);
        binding.backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.content, new Hand2AccessFragment());
        ft.commitAllowingStateLoss();

        binding.segmentControl.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
            @Override
            public void onSegmentControlClick(int index) {
                FragmentManager fm = getSupportFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                switch (index) {
                    case 0:
                        // 二手房
                        ft.replace(R.id.content, new Hand2AccessFragment());
                        ft.commitAllowingStateLoss();
                        break;
                    case 1:
                        //新房
                        ft.replace(R.id.content, new NewHouseAccessFragment());
                        ft.commitAllowingStateLoss();
                        break;
                    case 2:
                        //租房
                        ft.replace(R.id.content, new RentAccessFragment());
                        ft.commitAllowingStateLoss();
                        break;
                    default:
                        break;
                }
            }
        });

    }
}
